home *** CD-ROM | disk | FTP | other *** search
- /*
- File: CustomGet unresolved alias.c
-
- Contains: This sample demonstrates how to let the user choose an alias file
- from an "open" dialog. The basic idea is to intercept the pseudo-
- item 'sfHookOpenAlias' in a CustomGetFile hook function and transform
- it into 'getOpen'. This causes the dialog to behave as if the user
- had clicked the open button. Also, we intercept the item number of
- a check box we have added to the dialog item template in order to
- allow the user to choose whether to resolve aliases. Finally,
- when CustomGetFile returns, we call Alert to let the user know
- what happened.
-
- Written by: Pete Gontier
-
- Copyright: Copyright © 1999 by Apple Computer, Inc., All Rights Reserved.
-
- You may incorporate this Apple sample source code into your program(s) without
- restriction. This Apple sample source code has been provided "AS IS" and the
- responsibility for its operation is yours. You are not permitted to redistribute
- this Apple sample source code as "Apple sample source code" after having made
- changes. If you're going to re-distribute the source, we require that you make
- it clear in the source that the code was descended from Apple sample source
- code, but that you've made changes.
-
- Change History (most recent first):
- 7/1/1999 Karl Groethe Updated for Metrowerks Codewarror Pro 2.1
- 03/22/96 Use an alert, not DebugStr
- 03/22/96 in DlgHookYDProc, make sure we're dealing with
- main dialog before doing anything interesting
- 01/30/95 use AppendDITL instead of copy of System resources
- 01/25/95 initial version
-
-
-
- */
- #define OLDROUTINELOCATIONS 0
- #define OLDROUTINENAMES 0
- #define SystemSevenOrLater 1
-
- #ifndef __FONTS__
- # include <Fonts.h>
- #endif
-
- #ifndef __DIALOGS__
- # include <Dialogs.h>
- #endif
-
- #ifndef __STANDARDFILE__
- # include <StandardFile.h>
- #endif
-
- #ifndef __RESOURCES__
- # include <Resources.h>
- #endif
-
- static pascal OSErr InitMac (void)
- {
- MaxApplZone ( );
- InitGraf (&(qd.thePort));
- InitFonts ( );
- InitWindows ( );
- InitMenus ( );
- TEInit ( );
- InitDialogs (nil);
-
- return noErr;
- }
-
- static short gItemIndex_CustomGetCheckBox;
-
- enum
- {
- kResID_CustomGetCheckBox = 128,
- kResID_ReportResultsAlert
- };
-
- static pascal short DlgHookYDProc (short item, DialogRef dRef, void *)
- {
- if (GetWRefCon (dRef) == sfMainDialogRefCon)
- {
- if (item == sfHookFirstCall)
- {
- Handle checkBoxDitlH = GetResource ('DITL',kResID_CustomGetCheckBox);
- if (!ResError ( ) && checkBoxDitlH)
- {
- DetachResource (checkBoxDitlH);
- if (ResError ( ))
- ReleaseResource (checkBoxDitlH);
- else
- {
- gItemIndex_CustomGetCheckBox = 1 + CountDITL (dRef);
- AppendDITL (dRef,checkBoxDitlH,appendDITLBottom);
- DisposeHandle (checkBoxDitlH);
- }
- }
- }
- else if (item == gItemIndex_CustomGetCheckBox || item == sfHookOpenAlias)
- {
- short iType; Rect iRect; Handle iHandle; Boolean iValue;
- GetDialogItem (dRef,gItemIndex_CustomGetCheckBox,&iType,&iHandle,&iRect);
- iValue = GetControlValue ((ControlRef) iHandle);
- if (item != sfHookOpenAlias)
- SetControlValue ((ControlRef) iHandle, !iValue);
- else if (!iValue)
- item = getOpen;
- }
- }
-
- return item;
- }
-
- void main (void)
- {
- if (!InitMac ( ))
- {
- StandardFileReply sfr;
- Point sfWhere = {-1,-1};
- CustomGetFile (nil,-1,nil,&sfr,sfGetDialogID,sfWhere,NewDlgHookYDProc(DlgHookYDProc),nil,nil,nil,nil);
-
- if (sfr.sfGood)
- ParamText (sfr.sfFile.name,nil,nil,nil);
- else
- ParamText ("\pAs the world's worst singer would say: 'No reply at all.'",nil,nil,nil);
-
- Alert (kResID_ReportResultsAlert,nil);
- }
- }
-